package com.avic.rong.questionOrAnswer.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.avic.rong.R;
import com.avic.rong.questionOrAnswer.activity.PersonalHomeActivity;
import com.avic.rong.questionOrAnswer.bean.GetSupplyBean;
import com.avic.rong.utils.GlideUtils;

import java.util.List;

/**
 * Created by XinEr on 2019/8/7.
 * Describe:
 */
public class AchievementListAdapter extends RecyclerView.Adapter<AchievementListAdapter.ViewHolder> {
    private Context context;
    private List<GetSupplyBean> listData;


    public AchievementListAdapter(Context context, List<GetSupplyBean> listData) {
        this.context = context;
        this.listData = listData;


    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.achievement_list_item, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
        GetSupplyBean getSupplyBean = listData.get(i);
        //TODO 返回数据缺少字段
//        GlideUtils.loaderImage(context,getSupplyBean.get);
//            viewHolder.tv_name.setText();
        viewHolder.tv_date.setText(getSupplyBean.getPublishTime());
//        viewHolder.tv_sign.setText();
        viewHolder.tv_goods_price.setText("¥"+getSupplyBean.getPrice());
        GlideUtils.loaderImage(context,getSupplyBean.getFiles(),viewHolder.iv_goods_pic);
        if (!TextUtils.isEmpty(((PersonalHomeActivity)context).getLOGO())){
            GlideUtils.loaderHanldeRoundImage(context, ((PersonalHomeActivity)context).getLOGO(),viewHolder.ic_photo,80);
        }
        if (!TextUtils.isEmpty(((PersonalHomeActivity)context).getNAME())){
           viewHolder.tv_name.setText(((PersonalHomeActivity)context).getNAME());
        }
    }

    @Override
    public int getItemCount() {
        return listData.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView ic_photo;
        private TextView tv_name;
        private TextView tv_date;
        private TextView tv_sign;
        private ImageView iv_goods_pic;
        private TextView tv_goods_name;
        private TextView tv_goods_time;
        private TextView tv_goods_price;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ic_photo=itemView.findViewById(R.id.ic_photo);
            tv_name=itemView.findViewById(R.id.tv_name);
            tv_date=itemView.findViewById(R.id.tv_date);
            tv_sign=itemView.findViewById(R.id.tv_sign);
            iv_goods_pic=itemView.findViewById(R.id.iv_goods_pic);
            tv_goods_name=itemView.findViewById(R.id.tv_goods_name);
            tv_goods_time=itemView.findViewById(R.id.tv_goods_time);
            tv_goods_price=itemView.findViewById(R.id.tv_goods_price);
        }
    }
}
